package com.dodayum.dubbo;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.ServiceConfig;
import com.alibaba.dubbo.registry.RegistryService;

/**
 * @Author DoDayum
 * @Date 2024-01-24-21:34
 */
public class RegistryInfo {

    public ServiceConfig<RegistryService> serviceConfig;

    public RegistryInfo() {
        System.out.println("注册中心开始启动");
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName("my-registry");

        ProtocolConfig protocol = new ProtocolConfig();
        protocol.setName("dubbo");
        protocol.setPort(8000);
        protocol.setThreads(100);

        RegistryConfig registryConfig = new RegistryConfig(RegistryConfig.NO_AVAILABLE);
        registryConfig.setGroup("dubbo");

        serviceConfig = new ServiceConfig<>();
        serviceConfig.setApplication(applicationConfig);
        serviceConfig.setRegister(false);
        //group注意，要和<dubbo:registry group="dodayum" address="127.0.0.1:8000"/>里的group一致
        serviceConfig.setGroup("dodayum");
        serviceConfig.setRegistry(registryConfig);
        serviceConfig.setProtocol(protocol);
        serviceConfig.setInterface(RegistryService.class);
        serviceConfig.setRef(new MyRegistry());
        serviceConfig.setCallbacks(10000);
        serviceConfig.setOndisconnect("disconnect");
        serviceConfig.setTimeout(1000 * 60);

        serviceConfig.export();
        System.out.println("注册中心已启动");
    }

}
